﻿using System.ComponentModel.DataAnnotations;

namespace AiQiuQuan.Sport.Model.Models
{
    /// <summary>
    /// 学生点名
    /// </summary>
    public class CourseStudentRequestDto : IValidatableObject
    {
        /// <summary>
        /// 课程ID
        /// </summary>
        [Required]
        public Guid CourseId { get; set; }

        /// <summary>
        /// 点名
        /// </summary>
        [Required]
        [MinLength(1)]
        public List<CallStudentDto> CallStudentList { get; set; }

        /// <summary>
        /// validate
        /// </summary>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            foreach (var callStudent in CallStudentList)
            {
                if (callStudent.UseCount <= 0)
                {
                    yield return new ValidationResult("点名次数为0");
                    yield break;
                }

                if (CallStudentList.Count(m => m.UserId == callStudent.UserId) >= 2)
                {
                    yield return new ValidationResult("学生重复");
                    yield break;
                }
            }
        }
    }
}
